]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - Super Polarity/InputController.cs
Protoshow sprint.
[rbdr/super-polarity] / Super Polarity / InputController.cs
index ad07717b11c279778e35b72a1cde538692ff7081..c92bb9c37b8bc7500d8762d35d3c2fcf068428f3 100644 (file)
@@ -37,11 +37,42 @@ namespace SuperPolarity
 
         public static void UpdateInput()
         {
-            Poll();
             DispatchMoveEvents();
             DispatchRegisteredEvents();
         }
 
+        public static void UpdateInput(bool highPriorityOnly) 
+        {
+            Poll();
+            DispatchPauseEvent();
+            if (!highPriorityOnly)
+            {
+                UpdateInput();
+            }
+        }
+
+        public static void DispatchPauseEvent()
+        {
+            // OK THIS IS ALL KINDS OF WRONG. THIS IS A PLACEHOLDER BECAUSE DEMO!
+            var keyPressed = false;
+            if ((InputKeyboardState.IsKeyDown(Keys.Enter) || InputGamePadState.IsButtonDown(Buttons.Start))) {
+                keyPressed = true;
+                if(!BlockedButtons.Contains("pause") && !BlockedKeys.Contains("pause"))
+                {
+                    BlockedButtons.Add("pause");
+                    BlockedKeys.Add("pause");
+                    Console.WriteLine("Dispatch");
+                    Dispatch("pause", 0);
+                }
+            }
+
+            if (!keyPressed)
+            {
+                BlockedButtons.Remove("pause");
+                BlockedKeys.Remove("pause");
+            }
+        }
+
         private static void Poll()
         {
             InputGamePadState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
@@ -88,8 +119,8 @@ namespace SuperPolarity
                     {
                         if (!BlockedKeys.Contains(entry.Key))
                         {
-                            Dispatch(entry.Key, 1);
                             BlockedKeys.Add(entry.Key);
+                            Dispatch(entry.Key, 1);
                         }
                         keyFired = true;
                         break;
@@ -111,8 +142,8 @@ namespace SuperPolarity
                     {
                         if (!BlockedButtons.Contains(entry.Key))
                         {
-                            Dispatch(entry.Key, 1);
                             BlockedButtons.Add(entry.Key);
+                            Dispatch(entry.Key, 1);
                         }
                         keyFired = true;
                         break;
@@ -175,6 +206,21 @@ namespace SuperPolarity
             listenerList.Add(listener);
         }
 
+        public static void Unbind(string eventName, Action<float> listener)
+        {
+            List<Action<float>> listenerList;
+            bool foundListeners;
+
+            if (!Listeners.ContainsKey(eventName))
+            {
+                return;
+            }
+
+            foundListeners = Listeners.TryGetValue(eventName, out listenerList);
+
+            listenerList.Remove(listener);
+        }
+
         public static void Dispatch(string eventName, float value)
         {
             List<Action<float>> listenerList;
@@ -187,10 +233,16 @@ namespace SuperPolarity
                 return;
             }
 
-            foreach (Action<float> method in listenerList)
+            for (var i = listenerList.Count - 1; i >= 0; i--)
             {
-                method(value);
+                listenerList[i](value);
             }
         }
+
+        public static void Unlock(string eventName)
+        {
+            BlockedButtons.Remove(eventName);
+            BlockedKeys.Remove(eventName);
+        }
     }
 }